﻿package com.tudou.home.controller
{
    import com.tudou.ad.track.*;
    import com.tudou.consts.*;
    import com.tudou.cookie.*;
    import com.tudou.fast.*;
    import com.tudou.home.commands.*;
    import com.tudou.home.commands.ad.*;
    import com.tudou.home.controller.ad.*;
    import com.tudou.home.controller.macrocommand.*;
    import com.tudou.home.model.*;
    import com.tudou.home.model.ad.*;
    import com.tudou.home.track.*;
    import com.tudou.home.utils.*;
    import com.tudou.home.view.*;
    import com.tudou.home.view.ad.*;
    import com.tudou.js.*;
    import com.tudou.newPlayer.*;
    import com.tudou.track.*;
    import com.tudou.utils.*;
    import flash.display.*;
    import flash.system.*;
    import org.puremvc.as3.interfaces.*;
    import org.puremvc.as3.patterns.command.*;

    public class StartupCommand extends SimpleCommand implements ICommand
    {
        private var pageInfo:PageInfo;
        public static const NAME:String = "StartupCommand";

        public function StartupCommand()
        {
            pageInfo = PageInfo.getInstance();
            return;
        }// end function

        private function registerList() : void
        {
            if (!pageInfo.isListPlayer)
            {
                return;
            }
            facade.registerCommand(PlayListCommandSet.CHANGE_ITEM, PlayListCommand);
            facade.registerCommand(PlayListCommandSet.PLAY_LIST_LOADED, PlayListCommand);
            facade.registerCommand(PlayListCommandSet.NEXT_ITEM, PlayListCommand);
            facade.registerCommand(PlayListCommandSet.PREV_ITEM, PlayListCommand);
            facade.registerCommand(PlayListCommandSet.THIS_INDEX, PlayListCommand);
            facade.registerProxy(new PlayListProxy());
            return;
        }// end function

        private function registerCopyright() : void
        {
            facade.registerCommand(CopyrightCommandSet.SHOW_COPYRIGHT_PANEL, CopyrightCommand);
            facade.registerCommand(CopyrightCommandSet.CLOSE_COPYRIGHT_PANEL, CopyrightCommand);
            return;
        }// end function

        private function registerPrivacy() : void
        {
            var _loc_1:* = facade.retrieveMediator(ViewMediator.NAME) as ViewMediator;
            facade.registerMediator(new PrivacyMediator(_loc_1.privacyPanelSpace));
            facade.registerCommand(PrivacyCommandSet.SHOW_PRIVACY_PANEL, PrivacyCommand);
            facade.registerCommand(PrivacyCommandSet.HIDE_PRIVACY_PANEL, PrivacyCommand);
            facade.registerCommand(PrivacyCommandSet.RIGHT_PASSWORD, PrivacyCommand);
            facade.registerCommand(PrivacyCommandSet.WRONG_PASSWORD, PrivacyCommand);
            return;
        }// end function

        private function pageInfoUpdate() : void
        {
            var _loc_1:* = AOPTracker.getInst();
            pageInfo.updateRid();
            pageInfo.updateCvid();
            pageInfo.currRateType = RateType.UNDEFINED;
            _loc_1.startSendLog();
            return;
        }// end function

        private function registerView(param1:Sprite) : void
        {
            facade.registerMediator(new ViewMediator(param1));
            facade.registerCommand(ViewCommandSet.ENTER_FULLSCREEN_AND_RESIZE, EnterFullscreenCommand);
            facade.registerCommand(ViewCommandSet.NORMALSCREEN_RESIZE, ExitFullscreenCommand);
            facade.registerCommand(ViewCommandSet.EXPAND_STAGE, ExpandStageCommand);
            facade.registerCommand(ViewCommandSet.REAL_EXIT_FULLCREEN, RealExitFullscreenCommand);
            return;
        }// end function

        private function registerListSingle() : void
        {
            if (pageInfo.isListPlayer)
            {
                return;
            }
            facade.registerCommand(PlayListSingleCommandSet.CHANGE_ITEM, PlayListSingleCommand);
            facade.registerCommand(PlayListSingleCommandSet.NEXT_ITEM, PlayListSingleCommand);
            facade.registerCommand(PlayListSingleCommandSet.PREV_ITEM, PlayListSingleCommand);
            facade.registerCommand(PlayListSingleCommandSet.THIS_INDEX, PlayListSingleCommand);
            facade.registerCommand(PlayListSingleCommandSet.PLAY_LIST_LOADED, PlayListSingleCommand);
            facade.registerCommand(PlayListSingleCommandSet.SET_COOKIE_PLAYLIST_SINGLE_CONTINUE, PlayListSingleCommand);
            facade.registerProxy(new PlayListSingleProxy());
            return;
        }// end function

        private function registerPlayer() : void
        {
            var _loc_1:* = facade.retrieveMediator(ViewMediator.NAME) as ViewMediator;
            facade.registerMediator(new SkinMediator(_loc_1.playerSpace));
            var _loc_2:* = new PlayerProxy();
            _loc_2.debugURL = pageInfo.debugURL;
            facade.registerProxy(_loc_2);
            facade.registerCommand(PlayerCommandSet.PLAYER_INITED, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.PLAYER_CHANGE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.UPDATE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.FIRST_BUFFER_FULL, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.NOTIFY_SKIN_STATE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.PLAYER_EVENT, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.PLAY, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.PAUSE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.TOGGLE_PAUSE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.SHOW_PLAY_COMPLETE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.HIDE_PLAY_COMPLETE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.MUTE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.SET_VOLUME, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.END_SET_VOLUME, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.SET_BRIGHTNESS, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.END_SET_BRIGHTNESS, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.SEEK, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.VIDEO_LOAD_COMPLETE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.REPLAY, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.START_LOAD, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.START_PLAY, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.CHANGE_RATE_TYPE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.SET_COOKIE_RATE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.RATE_SETTING, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.INIT_INFO, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.SET_VIDEO_SCALE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.SET_ORIGINAL_VIDEO_SCALE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.SET_VIDEO_SIZE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.SET_VIDEO_ROTATE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.SET_CLOCK_WISE, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.PREVIEW, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.CLOSE_PREVIEW, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.PREVIEW_READY, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.BUTTON_LOG, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.TIMEOUT_START_PLAY, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.SET_COOKIE_SKIP, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.SKIP_SETTING, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.SKIPPING_HEAD, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.SKIPPING_TAIL, PlayerCommand);
            facade.registerCommand(PlayerCommandSet.VIDEO_FINISH, VideoCompleteMacroCommand);
            sendNotification(PlayerCommandSet.PLAYER_INITED);
            return;
        }// end function

        private function registerAd() : void
        {
            var _loc_1:* = facade.retrieveProxy(PlayerProxy.NAME) as PlayerProxy;
            ADTrackSender.getInstance().init(_loc_1.playerStatus, pageInfo);
            var _loc_2:* = facade.retrieveMediator(ViewMediator.NAME) as ViewMediator;
            var _loc_3:* = new AdProxy();
            _loc_3.adTracker = new TdAdTrack();
            facade.registerProxy(_loc_3);
            facade.registerProxy(new AdInfoProxy());
            facade.registerProxy(new AdListProxy());
            facade.registerProxy(new AdFrontMultiProxy());
            facade.registerProxy(new AdBackgroundProxy());
            facade.registerProxy(new AdPauseProxy());
            facade.registerProxy(new AdLoadingProxy(pageInfo));
            facade.registerProxy(new AdPlacardProxy());
            facade.registerProxy(new AdCornerProxy(pageInfo));
            facade.registerProxy(new AdOverlayProxy());
            facade.registerMediator(new AdLoadingMediator(_loc_2.loadingAdSpace));
            facade.registerMediator(new AdCptFloatMediator());
            facade.registerMediator(new AdCornerMediator());
            facade.registerCommand(AdCommandSet.CLEAR_ALL, AdCommand);
            facade.registerCommand(AdCommandSet.ADINFO_START_LOAD, AdCommand);
            facade.registerCommand(AdCommandSet.ADINFO_LOAD_COMPLETE, AdCommand);
            facade.registerCommand(AdCommandSet.ADINFO_LOAD_ERROR, AdCommand);
            facade.registerCommand(AdCommandSet.ADINFO_SECURITY_ERROR, AdCommand);
            facade.registerCommand(AdCommandSet.AD_CPT_FLOAT_LOADED, AdCommand);
            facade.registerCommand(AdCommandSet.AD_CPT_FLOAT_CLOSE, AdCommand);
            facade.registerCommand(AdCommandSet.AD_CPT_FLOAT_CLICK, AdCommand);
            facade.registerCommand(AdCommandSet.AD_CPT_FLOAT_SHOW, AdCommand);
            facade.registerCommand(AdCommandSet.AD_CPT_FLOAT_HIDE, AdCommand);
            facade.registerCommand(PlayerCommandSet.FULL_CACHED, AdCommand);
            facade.registerCommand(PlayerCommandSet.VIDEO_NEAR_FINISH, AdCommand);
            facade.registerCommand(AdCommandSet.ADLIST_CACHED, AdCommand);
            facade.registerCommand(AdFrontMultiCommandSet.START, AdFrontMultiCommand);
            facade.registerCommand(AdFrontMultiCommandSet.START_PLAY, AdFrontMultiCommand);
            facade.registerCommand(AdFrontMultiCommandSet.START_LOAD, AdFrontMultiCommand);
            facade.registerCommand(AdFrontMultiCommandSet.COMPLETE, AdFrontMultiCommand);
            facade.registerCommand(AdFrontMultiCommandSet.TIMEOUT_START_PLAY, AdFrontMultiCommand);
            facade.registerCommand(AdBackgroundCommandSet.START, AdBackgroundCommand);
            facade.registerCommand(AdBackgroundCommandSet.CLEAR, AdBackgroundCommand);
            facade.registerCommand(AdBackgroundCommandSet.ERROR_END, AdBackgroundCommand);
            facade.registerCommand(AdBackgroundCommandSet.PREPARE_TO_SHOW, AdBackgroundCommand);
            facade.registerCommand(AdBackgroundCommandSet.SHOW_START, AdBackgroundCommand);
            facade.registerCommand(AdBackgroundCommandSet.SHOW_END, AdBackgroundCommand);
            facade.registerCommand(AdPauseCommandSet.START, AdPauseCommand);
            facade.registerCommand(AdPauseCommandSet.CLEAR, AdPauseCommand);
            facade.registerCommand(AdPauseCommandSet.ERROR_END, AdPauseCommand);
            facade.registerCommand(AdPauseCommandSet.PREPARE_TO_SHOW, AdPauseCommand);
            facade.registerCommand(AdPauseCommandSet.SHOW_START, AdPauseCommand);
            facade.registerCommand(AdPauseCommandSet.SHOW_END, AdPauseCommand);
            facade.registerCommand(AdPlacardCommandSet.START, AdPlacardCommand);
            facade.registerCommand(AdPlacardCommandSet.CLEAR, AdPlacardCommand);
            facade.registerCommand(AdPlacardCommandSet.TIMEOUT_START_PLAY, AdPlacardCommand);
            facade.registerCommand(AdPlacardCommandSet.ERROR_END, AdPlacardCommand);
            facade.registerCommand(AdPlacardCommandSet.PREPARE_TO_SHOW, AdPlacardCommand);
            facade.registerCommand(AdPlacardCommandSet.SHOW_START, AdPlacardCommand);
            facade.registerCommand(AdPlacardCommandSet.SHOW_END, AdPlacardCommand);
            facade.registerCommand(AdPlacardCommandSet.SHOW_NEAR_END, AdPlacardCommand);
            facade.registerCommand(AdLoadingCommandSet.START, AdLoadingCommand);
            facade.registerCommand(AdLoadingCommandSet.CLEAR, AdLoadingCommand);
            facade.registerCommand(AdLoadingCommandSet.LOADING_LOAD_COMPLETE, AdLoadingCommand);
            facade.registerCommand(AdLoadingCommandSet.LOADING_SHOW_START, AdLoadingCommand);
            facade.registerCommand(AdLoadingCommandSet.LOADING_SHOW_COMPLETE, AdLoadingCommand);
            facade.registerCommand(AdLoadingCommandSet.LOADING_CLICK, AdLoadingCommand);
            facade.registerCommand(AdCornerCommandSet.START, AdCornerCommand);
            facade.registerCommand(AdCornerCommandSet.CLEAR, AdCornerCommand);
            facade.registerCommand(AdCornerCommandSet.AD_CLICK_CORNERAD, AdCornerCommand);
            facade.registerCommand(AdCornerCommandSet.AD_LOADER_READY, AdCornerCommand);
            facade.registerCommand(AdCornerCommandSet.AD_SHOW, AdCornerCommand);
            facade.registerCommand(AdOverlayCommandSet.START, AdOverlayCommand);
            facade.registerCommand(AdOverlayCommandSet.CLEAR, AdOverlayCommand);
            facade.registerCommand(AdOverlayCommandSet.ERROR_END, AdOverlayCommand);
            facade.registerCommand(AdOverlayCommandSet.PREPARE_TO_SHOW, AdOverlayCommand);
            facade.registerCommand(AdOverlayCommandSet.SHOW_START, AdOverlayCommand);
            facade.registerCommand(AdOverlayCommandSet.SHOW_END, AdOverlayCommand);
            return;
        }// end function

        private function registerTrack() : void
        {
            var _loc_1:* = PlayerProxy(facade.retrieveProxy(PlayerProxy.NAME)).playerStatus;
            var _loc_2:* = AOPTracker.getInst();
            _loc_2.init(pageInfo, _loc_1, UserSample.getInstance().isUTSSample());
            var _loc_3:* = GlobalTracker.getInst();
            _loc_3.init(pageInfo, _loc_1);
            HomeTrack.ins.init(_loc_1);
            return;
        }// end function

        private function boot(param1:Boolean) : void
        {
            var _loc_8:int = 0;
            var _loc_2:* = facade.retrieveProxy(PlayerProxy.NAME) as PlayerProxy;
            var _loc_3:* = facade.retrieveProxy(PlayListProxy.NAME) as PlayListProxy;
            var _loc_4:* = AOPTracker.getInst();
            var _loc_5:* = GlobalTracker.getInst();
            var _loc_6:* = StatusInfo.getInst();
            var _loc_7:* = PlayerSO.getInst();
            JSExchanger.getInst().notifyJS("loadItem");
            _loc_6.reset();
            if (param1 && pageInfo.isListPlayer)
            {
                _loc_3.loadPlayList();
            }
            _loc_2.reset();
            _loc_5.startSendLog();
            UserLog.getInst().reset();
            UserLog.getInst().addNode(NodeLog.PLAYER_START);
            _loc_4.addNodeLog(NodeLog.PLAYER_START, [encodeURIComponent(Capabilities.os), encodeURIComponent(pageInfo.userAgent), Capabilities.playerType, encodeURIComponent(Capabilities.version), Capabilities.isDebugger, Capabilities.language, Capabilities.screenResolutionX, Capabilities.screenResolutionY]);
            _loc_4.addNodeLog(NodeLog.PAGE_INFOS, [pageInfo.channelId]);
            if (pageInfo.needCount)
            {
                PlayTimeTracker.getInst().start(_loc_2.playerStatus, pageInfo);
            }
            sendNotification(PlayerCommandSet.INIT_INFO);
            sendNotification(PlayerCommandSet.SET_VIDEO_ROTATE, PlayerSO.getInst().rotateType);
            if (pageInfo.viewState != ViewState.FULLSCREEN)
            {
                sendNotification(ViewCommandSet.EXPAND_STAGE, pageInfo.expandStage, NAME);
                sendNotification(ViewCommandSet.NORMALSCREEN_RESIZE);
            }
            sendNotification(PlayerCommandSet.RATE_SETTING);
            if (param1 && pageInfo.playRate != RateType.UNDEFINED)
            {
                sendNotification(PlayerCommandSet.CHANGE_RATE_TYPE, RateUtil.correct(pageInfo.playRate, pageInfo.maxRateType, pageInfo.original));
            }
            else if (pageInfo.isListPlayer)
            {
                _loc_8 = _loc_7.listRateType;
                if (_loc_8 != RateType.UNDEFINED)
                {
                    sendNotification(PlayerCommandSet.CHANGE_RATE_TYPE, RateUtil.correct(_loc_8, pageInfo.maxRateType, pageInfo.original));
                }
            }
            if (pageInfo.isToll)
            {
                sendNotification(TollVideoCommandSet.VERIFY);
            }
            else if (pageInfo.isUserOwner)
            {
                sendNotification(CopyrightCommandSet.SHOW_COPYRIGHT_PANEL);
            }
            else if (pageInfo.isPrivate)
            {
                sendNotification(PrivacyCommandSet.SHOW_PRIVACY_PANEL);
            }
            else
            {
                sendNotification(CopyrightCommandSet.CLOSE_COPYRIGHT_PANEL);
                sendNotification(V2CommandSet.START_LOAD);
                sendNotification(AdCommandSet.ADINFO_START_LOAD);
            }
            return;
        }// end function

        private function initRegister(param1:Sprite) : void
        {
            PlayerSO.getInst().init(pageInfo);
            registerView(param1);
            registerPrivacy();
            registerToll();
            registerCopyright();
            registerList();
            registerListSingle();
            registerV2();
            registerPlayer();
            registerTrack();
            pageInfoUpdate();
            FastTudouNew.inst.connect();
            registerAd();
            registerPage();
            registerPreCommands();
            return;
        }// end function

        override public function execute(param1:INotification) : void
        {
            var _loc_2:Sprite = null;
            switch(param1.getName())
            {
                case ExternalCommandSet.START_UP:
                {
                    _loc_2 = param1.getBody() as Sprite;
                    initRegister(_loc_2);
                    boot(true);
                    break;
                }
                case ExternalCommandSet.BOOT:
                {
                    pageInfoUpdate();
                    boot(false);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function registerPreCommands() : void
        {
            facade.registerCommand(ExternalCommandSet.ADD_AD_FRONT, PreCommand);
            facade.registerCommand(ExternalCommandSet.REMOVE_AD_FRONT, PreCommand);
            facade.registerCommand(ExternalCommandSet.ADD_AD_BACK, PreCommand);
            facade.registerCommand(ExternalCommandSet.REMOVE_AD_BACK, PreCommand);
            facade.registerCommand(ExternalCommandSet.ADD_AD_FRONT_LAST, PreCommand);
            facade.registerCommand(ExternalCommandSet.REMOVE_AD_FRONT_LAST, PreCommand);
            return;
        }// end function

        private function registerPage() : void
        {
            facade.registerCommand(PageCommandSet.PAGE_LOADED, PageCommand);
            facade.registerCommand(PageCommandSet.LOAD_SHARE_RELATIVE_DATA, PageCommand);
            facade.registerCommand(PageCommandSet.GET_LIVE_DATA, PageCommand);
            var _loc_1:* = PlayerProxy(facade.retrieveProxy(PlayerProxy.NAME)).playerStatus;
            var _loc_2:* = new PageProxy(_loc_1);
            facade.registerProxy(_loc_2);
            _loc_2.checkPageLoaded();
            return;
        }// end function

        private function registerToll() : void
        {
            facade.registerProxy(new TollVideoProxy());
            facade.registerMediator(new TollVideoMediator());
            facade.registerCommand(TollVideoCommandSet.VERIFY, TollVideoCommand);
            facade.registerCommand(TollVideoCommandSet.VERIFY_FAILED, TollVideoCommand);
            facade.registerCommand(TollVideoCommandSet.VERIFY_SUCCEED, TollVideoCommand);
            return;
        }// end function

        private function registerV2() : void
        {
            facade.registerProxy(new V2Proxy());
            facade.registerCommand(V2CommandSet.START_LOAD, V2Command);
            facade.registerCommand(V2CommandSet.INFO_LOADED, V2Command);
            facade.registerCommand(V2CommandSet.INFO_ERROR, V2Command);
            return;
        }// end function

    }
}
